import React from 'react';
import * as THREE from 'three';
import Scene from '../Scene';
import vertexShader from './shaders/fireflies/vertex.glsl';
import fragmentShader from './shaders/fireflies/fragment.glsl';
import style from '../FrozenStation.css';

export default class TubeMesh {
    constructor(){
        this.scene = new Scene();
        this.canvasScene = this.scene.scene;
        this.resources = this.scene.resources;
        this.model = this.resources.items.room;
        this.renderer = this.scene.renderer;
        this.time = this.scene.time;
        this.sizes = this.scene.sizes;
        this.camera = this.scene.camera.perspectiveCamera;
        this.setModel();
    }
    setModel(){
        console.log(this.resources.items);
        // 设置纹理对象的色彩空间，保证跟烘焙图的色彩空间一致都是sRGB;
        this.resources.items.bake.encoding = THREE.sRGBEncoding;
        this.resources.items.bake.flipY = false;
        // this.resources.items.bake.wrapS = THREE.RepeatWrapping;
        // this.resources.items.bake.wrapT = THREE.RepeatWrapping;
        let mtl = new THREE.MeshBasicMaterial({
            map:this.resources.items.bake,
            side:THREE.DoubleSide,
        })
        let group = this.model.scene;
        group.children.forEach(mesh=>{
            if ( mesh.name === 'ground') {
                mesh.material = new THREE.MeshStandardMaterial({
                    color:0x303539,
                    roughness:0.1,
                    metalness:0.1,
                    transparent: true,
                    opacity:0.4,
                });
            } else {
                mesh.material = mtl;

            }
        })
        console.log(this.model);
        this.canvasScene.add(group); 
        // 配置场景的环境贴图
        this.resources.items.hdr.flipY = false;
        this.resources.items.hdr.mapping = THREE.EquirectangularReflectionMapping;
        this.canvasScene.environment = this.resources.items.hdr;
    }
    update(){
        if ( this.resources.items.bake ) {
            // this.resources.items.bake.offset.y -= 0.001;
        }
    }
}